﻿namespace SharpGym.Silverlight.Views
{
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Navigation;
    using SharpService;

    public partial class RegistrosDiarios : Page
    {
        public RegistrosDiarios()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Busy.IsBusy = true;
            App.Client.ReadAlunosAsync();
            App.Client.ReadAlunosCompleted += ClientOnReadAlunosCompleted;
        }

        private void ClientOnReadAlunosCompleted(object sender, ReadAlunosCompletedEventArgs e)
        {
            //Load your data here and assign the result to the CollectionViewSource.
            var myCollectionViewSource = (CollectionViewSource)Resources["alunoDtoViewSource"];
            myCollectionViewSource.Source = e.Result.OrderBy(a => a.Nome);
            AlunosList.SelectedIndex = -1;
            Busy.IsBusy = false;
        }

        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
        }

        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
        }

        private void AlunosList_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
        }

        private void Busy_OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
        }
    }
}